package com.hackordie.commons.game.player;

import java.util.ArrayList;
import java.util.List;

import com.hackordie.commons.hardware.computer.IComputer;

public class PlayersControl {

    List<Player> playersOnline = new ArrayList<Player>();

    public void addPlayer(String name, IComputer pc) {

        // agregamos el jugador si ese nombre no existe
        boolean existe = false;
        int pos = 0;

        while(!existe && pos < playersOnline.size()) {
            if (playersOnline.get(pos).name.equals(name)) {
                existe = true;
            }
            pos++;
        };

        if (!existe) {
            playersOnline.add(new Player(name, pc));

        }
    }

    public void deletePlayer(String name) {
        for (int i = 0; i < playersOnline.size(); i++) {
            if (playersOnline.get(i).name.equals(name)) {
                playersOnline.remove(i);
            }
        }
    }

    public List<Player> getPlayersOnline() {
        return playersOnline;
    }
    
    public Player getPlayerByName(String name) {
        
        for(int i = 0; i < playersOnline.size(); i++) {
            if(playersOnline.get(i).getName().equals(name)) {
                return playersOnline.get(i);
            }
        }
        return null;
    }
}
